<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('店铺转让')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ShopOffUser-add">
        <input th:value="${shopId}" id="shopId" hidden>
        <input th:value="${wxUserId}" id="wxUserId" hidden>
        <input  id="newWxUserId" hidden>
        <h4 class="form-header h4">公众号用户</h4>
        <div class="row">
            <div class="col-sm-9">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">手机号码：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input id="phoneNum" placeholder="请输入手机号码进行查询" class="form-control"
                                   type="text" maxlength="11" required >
                            <span class="input-group-addon" onclick="searchVip()"><i class="fa fa-search" ></i></span>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-9">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">微信昵称：</label>
                    <div class="col-sm-8">
                        <input name="nickName" id="nickName" placeholder="用户公众号昵称" class="form-control" type="text" maxlength="30"
                               required readonly>
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>转 让
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script type="text/javascript">
    var prefix = ctx + "/WxShop/WxShop";
    $("#form-ShopOffUser-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        $.modal.confirm("确认要将此商铺转让其用户吗",function () {
            var data={
                shopId :$("#shopId").val(),
                newWxUserId : $("#newWxUserId").val(),
                wxUserId : $("#wxUserId").val()
            }
            $.operate.post(prefix + "/changeShopWxUser", data,function (res) {
                if (res.code==0){
                    $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
                } else {
                    $.modal.alertWarning(result.msg)
                }
            });
        })
    }

    function searchVip() {
        $("#nickName").val('')
        $("#newWxUserId").val('')
        var phoneNum=  $('#phoneNum').val()
        if (!phoneNum){
            $.modal.alertWarning("请输入手机号进行查找")
            return false
        }
        $.ajax({
            url:prefix+"/searchUser",
            type: 'post',
            data: {phoneNum:phoneNum},
            dataType: "json",
            beforeSend:function(){
                $.modal.loading("正在查询信息中，请稍后...");
            },
            success: function(res) {
                $.modal.closeLoading()
                if (res.code==0){
                    if (res.data){
                        $("#nickName").val(res.data.nickName)
                        $("#newWxUserId").val(res.data.id)
                    }
                } else {
                    $.modal.alertWarning(res.msg)
                }
            }
        });

    }
</script>
</body>
</html>